#ifndef __DDVData__
#define __DDVData__

#include <fstream>
#include <map>
#include <set>
#include "TObject.h"
#include "TH1F.h"
#include "TCanvas.h"

using namespace std;

class DDVData {

public:
  
  DDVData();
  virtual ~DDVData();

  virtual int Initialize() = 0;
  virtual int GoToEvent( int n ) = 0;
  virtual void TearDown() = 0;
  map<int,TH1F*> GetCurrentTrace(void);
  
  class general_header
  {
  public:
    virtual void read_header(fstream* data_file) = 0;

    //==========Sets and gets==========//
    //---All Channels---//
    void set_num_traces(unsigned int num_traces_arg);
    unsigned int get_num_traces(void);
    void set_num_channels(unsigned int num_channels_arg);
    unsigned int get_num_channels(void);
    set<int>* get_channels(void);
    virtual int add_channel(int channel)=0;
    virtual int remove_channel(int channel)=0;
    //---Channel Specific---//
    void set_samples_per_trace(int channel, unsigned int samples_per_trace_arg);
    unsigned int get_samples_per_trace(int channel);
    void set_bits_per_sample(int channel, unsigned int bits_per_sample_arg);
    unsigned int get_bits_per_sample(int channel);
    void set_time_per_sample(int channel, double time_per_sample_arg);
    double get_time_per_sample(int channel);
    void set_trigger_offset(int channel, double trigger_offset_arg);
    double get_trigger_offset(int channel);
    void set_volts_per_sample(int channel, double volts_per_sample_arg);
    double get_volts_per_sample(int channel);
    void set_voltage_offset(int channel, double voltage_offset_arg);
    double get_voltage_offset(int channel);
    //=================================//
    
    //---File Info---//
    long unsigned int header_size;
    long unsigned int trace_size;
    
    
  protected:
    //---All Channels---//
    set<int> channels;
    unsigned int num_traces;
    unsigned int num_channels;
    
    //---Channel Specific---//
    map<int, unsigned int> samples_per_trace;
    map<int, unsigned int> bits_per_sample;
    map<int, double> time_per_sample;
    map<int, double> trigger_offset;
    map<int, double> volts_per_sample;
    map<int, double> voltage_offset;
  };
  
  general_header * get_header(void);
  
protected:

  general_header * header;

  map<int,TH1F*> current_trace;

  int m_DataEventID;
  fstream* data_file;

  void define_histogram(int channel, string name1, string name2, int nbins, float lowbound, float highbound);


};

#endif
